function newIm=myWarp(im,H)
% function newIm=myWarp(im,T)
%check args
% if nargin==3
%     T=[1 0 dx;0 1 dy;0 0 1];
% else
%     T=[cos(da) -sin(da) dx;sin(da) cos(da) dy;0 0 1];
% end;
%newIm=zeros(size(im));
% [X,Y]=meshgrid(1:size(im,2),1:size(im,1));
% 
% [XI,YI]=meshgrid(1-dx:1:size(im,2)-dx,1-dy:1:size(im,1)-dy);
% 
% newIm=interp2(X,Y,im,XI,YI,'bilinear');
% ind=find(isnan(newIm));
% newIm(ind)=0;
H=inv(H);
 m = size(im,1); n = size(im,2); o = size(im, 3);
  
  newIm = zeros(m, n, o);

       [X,Y] = meshgrid(1:n, 1:m);

%       [X,Y]=meshgrid(floor(-n/2+1):floor(n/2),floor(-m/2+1):floor(m/2));
       % [X,Y]=meshgrid(-(n-1)/2:(n-1)/2,-(m-1)/2:(m-1)/2);
%   end;
  tPixels = H*[X(:)';Y(:)';ones(1, m*n)];
  tPixels(1,:)=tPixels(1,:)./tPixels(end,:);
  tPixels(2,:)=tPixels(2,:)./tPixels(end,:);
  Xi = reshape(tPixels(1,:), m, n);
  Yi = reshape(tPixels(2,:), m, n);
  for i = 1:o
    newIm(:,:,i) = interp2(X, Y, im(:,:,i), Xi, Yi);
  end
  ind=find(isnan(newIm));
  newIm(ind)=0;
  %newIm(~isfinite(Inew)) = 0;